package net.sky.oa.service.infopub.impl;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sky.oa.dao.infopub.InfNoticeDao;
import net.sky.oa.model.InfNotice;
import net.sky.oa.service.infopub.InfNoticeService;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.htsoft.core.service.impl.BaseServiceImpl;
import com.htsoft.core.web.paging.PagingBean;

@Service
@Transactional
public class InfNoticeServiceImpl extends BaseServiceImpl<InfNotice>
		implements InfNoticeService {

	private InfNoticeDao infNoticeDao;

	@Resource
	public void setInfNoticeDao(InfNoticeDao infNoticeDao) {
		super.setDao(infNoticeDao);
		this.infNoticeDao = infNoticeDao;
	}
	
	public List<InfNotice> getDisplay(PagingBean pb,Integer status,Integer sort) {
		return this.infNoticeDao.getDisplay(pb,status,sort);
	}
	/**
	 * 1.查询公司公告,需求:根据title,user[name],rank,createTime(begin、end),type查所有status为1的公告  sort=2
	 * 2.查询发布公告,需求:根据title,rank,type查我的(current user)公告  sort=2
	 * 3.查询公司通知,需求:根据title,user[name],rank,createTime(begin、end),type查所有status为1且发给我通知  sort=1
	 * 4.查询发布通知,需求:根据title,rank,type查我的(current user)发出的通知  sort=1
	 * 5.查询公告管理,需求:根据title,userName,rank,createTime(begin、end),type查所有status为1的公告  sort=2
	 * 6.查询通知管理,需求:根据title,userName,rank,createTime(begin、end),type查所有status为1的通知  sort=1
	 */
	public List<InfNotice> findByParams(Long userId,Integer opType,HttpServletRequest request,PagingBean pb)
	{
		/**
		 * title;userName,rank,type,sort,beginTime,endTime均可从request中获得
		 */
		String title=request.getParameter("Q_title_S_LK");
		String userName=request.getParameter("Q_user.name_S_LK");
		String beginTime=request.getParameter("Q_createtime_D_GE");
		String endTime=request.getParameter("Q_createtime_DG_LE");
		String ntRank=request.getParameter("Q_rank_N_EQ");
		String ntType=request.getParameter("Q_type.id_L_EQ");
		String ntSort=request.getParameter("Q_sort_N_EQ");
		Integer rank=StringUtils.isBlank(ntRank)?-1:Integer.valueOf(ntRank);
		Long type=StringUtils.isBlank(ntType)?-1:Long.valueOf(ntType);
		Integer sort=StringUtils.isBlank(ntSort)?-1:Integer.valueOf(ntSort);
		
		return infNoticeDao.findByParams(title, userName, rank, type, sort, userId, opType, beginTime, endTime, pb);
	}
}
